/**
 * Created by ZT on 2018/12/3 0003.
 */


/****
 login请求
 **/
const sqls = require('../sqlMap');  //对应的mysql语句
const query = require('../db');
const mysql = require('mysql');
const querystring = require('querystring');
const jwt = require('jsonwebtoken');
const jwtSecret = 'zt-secret';  //jwt密码
const path = require('path');
exports.loginPage =(req,res,next)=>{
      let params = req.body;
      let _sql = sqls.findData('zt_admin','where username=? and password=?');
      _sql = mysql.format(_sql,[params['username'],params['passwd']]);
      let results={};
      query.connect(_sql,function (err,result) {
         if(err){
             results = {ret:0,msg:'用户名或密码错误'};
             res.send(results);
         }else{
             let results ='';
             if(result.length>0){
                 const token = jwt.sign({username:result[0]['username']},jwtSecret,{expiresIn:60*60*24});
                 results ={ret:1,user:result[0]['username'],access_token:token};
             }else{
                 results = {ret:0,msg:'用户名或密码错误'};
             }
             res.send(results);
         }
      })
}
exports.logout=(req,res,next)=>{


}